<?php

/* 库存 */
class AdminstockModel extends BaseModel
{
    var $table  = 'adminstock';
    var $prikey = 'adminstock_id';
    var $_name  = 'adminstock';

    /* 添加编辑时自动验证 */
    var $_autov = array(
        'stock_name' => array(
            'required'  => true,    //必填
            'min'       => 1,       //最短1个字符
            'max'       => 100,     //最长100个字符
            'filter'    => 'trim',
        ),
    );
    function drop($conditions, $fields = 'ad_logo')
    {
        $droped_rows = parent::drop($conditions, $fields);
        if ($droped_rows)
        {
            restore_error_handler();
            $droped_data = $this->getDroppedData();
            foreach ($droped_data as $key => $value)
            {
                if ($value['ad_logo'])
                {
                    @unlink(ROOT_PATH . '/' . $value['ad_logo']);  //删除Logo文件
                }
            }
            reset_error_handler();
        }

        /**
         * 取得信息
         */
        function get_info($adminstock_id)
        {
            $info = $this->get(array(
                'conditions' => $adminstock_id,
            ));
            if (!empty($info['certification']))
            {
                $info['certifications'] = explode(',', $info['certification']);
            }
            return $info;
        }
        return $droped_rows;
    }

}

?>